package com.irdstudio.efp.esb.service.mock.hj;


import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.irdstudio.efp.esb.common.client.resp.EsbRespServiceBean;
import com.irdstudio.efp.esb.common.constant.EsbBizEnums;
import com.irdstudio.efp.esb.service.bo.req.hj.ReqCusInfoCreBean;
import com.irdstudio.efp.esb.service.bo.resp.hj.RespCusInfoCreBean;
import com.irdstudio.efp.esb.service.client.ESBClientFactory;
import com.irdstudio.efp.esb.service.facade.hj.CustomerInfoCreateService;
import com.irdstudio.basic.framework.core.exception.BizException;
import com.irdstudio.basic.framework.core.util.StringUtil;

/**
 * 用户及客户信息建立接口实现类
 * 
 * @author qiuyf
 * @since 2018年12月20日 下午7:42:50
 * @version 1.0
 */
@Service("customerInfoCreateService")
public class CustomerInfoCreateServiceImpl implements CustomerInfoCreateService {

	Logger logger = LoggerFactory.getLogger(CustomerInfoCreateServiceImpl.class);

	/**
	 * @description:用户及客户信息建立
	 * @param reqCusInfoCreBean
	 * @return
	 * @date:2018年12月21日 下午3:26:09
	 * @author:wangyk3
	 */
	@Override
	public RespCusInfoCreBean customerInfoCreate(ReqCusInfoCreBean reqCusInfoCreBean) throws Exception {
		// 返回对象
		//RespCusInfoCreBean respCusInfoCreBean = null;
		logger.info("根据证件号码：" + reqCusInfoCreBean.getCertNo() + "前往互金建立客户信息开始................");
		/*try {
			
			// 1.发送请求信息--> ESB
			EsbRespServiceBean  esbRespServiceBean = ESBClientFactory.buildClient().withBody(reqCusInfoCreBean).withTradeNo("20120001").withScene("01").create().sendAndReceive();
			if(EsbBizEnums.RetCodeEnum.SUCCESS.VALUE.equals(esbRespServiceBean.getSysHead().getRetInfArry().get(0).getRetCd())) {
				respCusInfoCreBean = esbRespServiceBean.getBody(RespCusInfoCreBean.class);
				// 2.1  判断是否有正常客户号返回
				if (StringUtil.isEmpty(respCusInfoCreBean.getClntNo())) { // 若为空
					throw new BizException("调用用户及客户信息建立接口异常，返回客户号为空！");
				}
				// 2.2 判断是否有正常用户号返回
				if (StringUtil.isEmpty(respCusInfoCreBean.getUsrID())) {  // 若为空
					throw new BizException("调用用户及客户信息建立接口异常，返回用户号为空！");
				}
			}
		}catch (Exception e) {
			logger.error(e.getMessage());
			throw e;
		}*/
		
		RespCusInfoCreBean respCusInfoCreBean = new RespCusInfoCreBean();
		respCusInfoCreBean.setClntNo(UUID.randomUUID().toString().substring(0, 20));
		respCusInfoCreBean.setUsrID(UUID.randomUUID().toString().substring(0, 30));
		logger.info("根据证件号码：" + reqCusInfoCreBean.getCertNo() + "前往互金建立客户信息结束!");
		return respCusInfoCreBean;
	}
}
